﻿<!DOCTYPE html>
<html>
<head>
    <title>JS Functions Exercise 1</title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <h1>Function that returns the last digit of given integer as an English word</h1>
    <label for="num-input">Number:</label>
    <input type="text" id="num-input" />
    <button onclick="execute()">Execute</button>
    <div id="js-console"></div>
    <script src="scripts/js-console.js"></script>
    <script>
        function lastNumberDigit(number)
        {
            switch (number % 10)
            {
                case 0:
                    return "zero";
                case 1:
                    return "one";
                case 2:
                    return "two";
                case 3:
                    return "three";
                case 4:
                    return "four";
                case 5:
                    return "five";
                case 6:
                    return "six";
                case 7:
                    return "seven";
                case 8:
                    return "eight";
                case 9:
                    return "nine";
                default:
                    return "not a number";
            }
        }

        function execute()
        {
            var num = jsConsole.readInteger("#num-input");
            jsConsole.writeLine(lastNumberDigit(num));
        }
        
    </script>
</body>
</html>
